﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Camc.OutsourceProcession.Configuration;
using Camc.OutsourceProcession.Web;

namespace Camc.OutsourceProcession.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class OutsourceProcessionDbContextFactory : IDesignTimeDbContextFactory<OutsourceProcessionDbContext>
    {
        public OutsourceProcessionDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<OutsourceProcessionDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder(), addUserSecrets: true);

            OutsourceProcessionDbContextOptionsConfigurer.Configure(builder, 
				configuration.GetConnectionString(OutsourceProcessionConsts.ConnectionStringName));

            return new OutsourceProcessionDbContext(builder.Options);
        }
    }
}